package com.javabi.htmlbuilder.html.element;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLDocument;
import com.javabi.htmlbuilder.html.HTMLElement;
import com.javabi.htmlbuilder.html.HTMLElementName;
import com.javabi.htmlbuilder.html.element.head.Title;

/**
 * A HTML Head Element.
 * <p>
 * &lt;table&gt; ... &lt;/table&gt;
 * </p>
 * @see HTMLDocument
 * @see Body
 */
public class Head extends HTMLElement<Head> {

	/** The title. */
	private Title title = null;
	/** The style. */
	private StyleSet styleSet = null;

	/**
	 * Sets the title for this head element.
	 * @param title the title.
	 * @return this head element.
	 */
	public Head title(String title) {
		if (title == null) {
			throw new NullPointerException();
		}
		this.title = new Title(title);
		return this;
	}

	/**
	 * Returns the title for this head element.
	 * @return this title.
	 */
	public Title title() {
		if (title == null) {
			throw new NullPointerException();
		}
		this.title = new Title();
		return title;
	}

	/**
	 * Add the styles tag.
	 * @return the tag.
	 */
	public StyleSet styleSet() {
		this.styleSet = new StyleSet();
		return styleSet;
	}

	/**
	 * Returns true to format this element.
	 * @return true to format this element.
	 */
	public boolean format() {
		return true;
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public HTMLElementName getElementName() {
		return HTMLElementName.HEAD;
	}

	/**
	 * Append this to the given html builder.
	 * @param html the html builder.
	 * @return the html builder.
	 */
	public HTMLBuilder appendTo(HTMLBuilder html) {
		html.open(this, false);
		appendInlineStyleAttributesTo(html);
		if (title != null) {
			title.appendTo(html);
		}
		if (styleSet != null) {
			styleSet.appendTo(html);
		}
		html.close(this);
		return html;
	}

}
